/* Smooth scrolling para anclas */
$(document).on('click','a.smooth', function(e){
    e.preventDefault();
    var $link = $(this);
    var anchor = $link.attr('href');
    $('html, body').stop().animate({
        scrollTop: $(anchor).offset().top
    }, 1000);
});

(function($) {
    $(document).ready(function() {
      $.slidebars();
      $('[rel="tooltip"]').tooltip();
      $('[rel="popover"]').popover();
    });
}) (jQuery);

(function( $ ) {

    var $container = $('.masonry-container');
    $container.imagesLoaded( function () {
        $container.masonry({
            columnWidth: '.masonry-item',
            itemSelector: '.masonry-item'
        });
    });
    
})(jQuery);

// Syntax Enable
/*SyntaxHighlighter.all();*/

jQuery(document).ready(function () {
    $('.nav').on('click mousedown mouseup touchstart touchmove', 'a.has_children', function () {
        if ( $(this).next('ul').hasClass('open_t') && !$(this).parents('ul').hasClass('open_t')) {
            $('.open_t').removeClass('open_t');
            return false;
        }
        $('.open_t').not($(this).parents('ul')).removeClass('open_t');
        $(this).next('ul').addClass('open_t');
        return false;
    });
    $(document).on('click', ':not(.has_children, .has_children *)', function() {
        if( $('.open_t').length > 0 ) {
            $('.open_t').removeClass('open_t');
            $('.open_t').parent().removeClass('open');
            return false;
        }
    });

    // hide #back-top first
    $("#back-top").hide();

    // fade in #back-top
    $(function () {
        $(window).scroll(function () {
            if ($(this).scrollTop() > 100) {
                $('#back-top').fadeIn();
            } else {
                $('#back-top').fadeOut();
            }
        });

        // scroll body to 0px on click
        $('#back-top a').click(function () {
            $('body,html').animate({
                scrollTop: 0
            }, 500);
            return false;
        });
    });
////
    
});

// WOW Activate
new WOW().init();

jQuery(document).ready(function() { // makes sure the whole site is loaded
    $('#status').fadeOut(); // will first fade out the loading animation
    $('#preloader').delay(350).fadeOut('slow'); // will fade out the white DIV that covers the website.
    $('body').delay(350).css({'overflow':'visible'});
});


// full-width-checkbox
$("[name='full-width-checkbox']").bootstrapSwitch();


/**
* jQuery scroroller Plugin 1.0
*
* http://www.tinywall.net/
* 
* Developers: Arun David, Boobalan
* Copyright (c) 2014 
*/
(function($){
    $(window).on("load",function(){
        $(document).scrollzipInit();
        $(document).rollerInit();
    });
    $(window).on("load scroll resize", function(){
        $('.numscroller').scrollzip({
            showFunction    :   function() {
                                    numberRoller($(this).attr('data-slno'));
                                },
            wholeVisible    :     false,
        });
    });
    $.fn.scrollzipInit=function(){
        $('body').prepend("<div style='position:fixed;top:0px;left:0px;width:0;height:0;' id='scrollzipPoint'></div>" );
    };
    $.fn.rollerInit=function(){
        var i=0;
        $('.numscroller').each(function() {
            i++;
           $(this).attr('data-slno',i); 
           $(this).addClass("roller-title-number-"+i);
        });        
    };
    $.fn.scrollzip = function(options){
        var settings = $.extend({
            showFunction    : null,
            hideFunction    : null,
            showShift       : 0,
            wholeVisible    : false,
            hideShift       : 0,
        }, options);
        return this.each(function(i,obj){
            $(this).addClass('scrollzip');
            if ( $.isFunction( settings.showFunction ) ){
                if(
                    !$(this).hasClass('isShown')&&
                    ($(window).outerHeight()+$('#scrollzipPoint').offset().top-settings.showShift)>($(this).offset().top+((settings.wholeVisible)?$(this).outerHeight():0))&&
                    ($('#scrollzipPoint').offset().top+((settings.wholeVisible)?$(this).outerHeight():0))<($(this).outerHeight()+$(this).offset().top-settings.showShift)
                ){
                    $(this).addClass('isShown');
                    settings.showFunction.call( this );
                }
            }
            if ( $.isFunction( settings.hideFunction ) ){
                if(
                    $(this).hasClass('isShown')&&
                    (($(window).outerHeight()+$('#scrollzipPoint').offset().top-settings.hideShift)<($(this).offset().top+((settings.wholeVisible)?$(this).outerHeight():0))||
                    ($('#scrollzipPoint').offset().top+((settings.wholeVisible)?$(this).outerHeight():0))>($(this).outerHeight()+$(this).offset().top-settings.hideShift))
                ){
                    $(this).removeClass('isShown');
                    settings.hideFunction.call( this );
                }
            }
            return this;
        });
    };
    function numberRoller(slno){
            var min=$('.roller-title-number-'+slno).attr('data-min');
            var max=$('.roller-title-number-'+slno).attr('data-max');
            var timediff=$('.roller-title-number-'+slno).attr('data-delay');
            var increment=$('.roller-title-number-'+slno).attr('data-increment');
            var numdiff=max-min;
            var timeout=(timediff*1000)/numdiff;
            //if(numinc<10){
                //increment=Math.floor((timediff*1000)/10);
            //}//alert(increment);
            numberRoll(slno,min,max,increment,timeout);
            
    }
    function numberRoll(slno,min,max,increment,timeout){//alert(slno+"="+min+"="+max+"="+increment+"="+timeout);
        if(min<=max){
            $('.roller-title-number-'+slno).html(min);
            min=parseInt(min)+parseInt(increment);
            setTimeout(function(){numberRoll(eval(slno),eval(min),eval(max),eval(increment),eval(timeout))},timeout);
        }else{
            $('.roller-title-number-'+slno).html(max);
        }
    }
})(jQuery);

$('.col-megamenu').matchHeight({
    byRow: true,
    property: 'height',
    target: null,
    remove: false
});
//.project-people  弹出框
function ContentMethod(id) {
	 var m ;
	 $.ajax( {
			url : ctx+"/sys/user/userInfo.json",				
			dataType : "json",
			type:"post",
			data : {id : id},
			async:false,
			contentType: "application/x-www-form-urlencoded; charset=UTF-8",
			success : function(data) {
				var name=data.name==undefined?"":data.name;    // 姓名
				var officeName="";   // 部门
				for(var o in data.officeList){
					officeName+= data.officeList[o].name+">";
				}
				officeName+=data.office==undefined?"":data.office.name;
				var email=data.email==undefined?"":data.email;	// 邮箱
				var phone=data.phone==undefined?"":data.phone;	// 电话
				var mobile=data.mobile==undefined?"":data.mobile;
				var photo = data.photo ==undefined?"":data.photo;
				var position = data.position ==undefined?"":data.position.name;
				m= "<div><h4>"+
				"<img  class='img-circle'   src='"+photo+"' onError=\"this.src='"+ctxStatic+"/bootstrap/assets/img/demo/no-user.png';\" width='47px' height='47px'>"+
					name+"</h4><br>"+
					"<span style=\"font-size:13px\">部门："+officeName+"</span><br>"+
					"<span style=\"font-size:13px\">职务："+position+"</span><br>"+
					"<span style=\"font-size:13px\">电话："+phone+"</span><br>"+
					"<span style=\"font-size:13px\">手机："+mobile+"</span><br>"+
					"<span style=\"font-size:13px\">邮箱："+email+"</span><br></div>";		          
			}
   }); 
	return m;
}	
/************************客户信息弹出框start**************************************/
jQuery(document).ready(function () {
	$(".popover-attrclient").popover({
	    trigger:'manual',
	    placement : 'right', //placement of the popover. also can use top, bottom, left or right
	    title : '', //this is the top title bar of the popover. add some basic css
	    html: 'true', //needed to show html of course
	    content : '', //this is the content of the html box. add the image here or anything you want really.
	    animation: false
	}).on("mouseenter", function () {
	            var _this = this;
	            var id = $(this).attr('id');
	            var Content1 = getClientInfo(id)//"<div>"+id+"</div>"
	            $(this).attr("data-content",Content1);
				 $(this).popover("show");
	            $(this).siblings(".popover").on("mouseleave", function () {
	                $(_this).popover('hide');
	            });  
	           
	}).on("mouseleave", function () {
	    var _this = this;
	    setTimeout(function () {
	        if (!$(".popover:hover").length) {
	            $(_this).popover("hide")
	        }
	    }, 100);
	});
});
function getClientInfo(id) {
	 var m ;
	 $.ajax( {
			url : ctx+"/client/proClient/clientInfo.json",				
			dataType : "json",
			type:"post",
			data : {id : id},
			async:false,
			contentType: "application/x-www-form-urlencoded; charset=UTF-8",
			success : function(data) {
				var name=data.name==undefined?"":data.name;    // 客户名称
				var category = data.category==undefined?"":data.category.name; //行业
				var address =data.address==undefined?"":data.address;		// 地址
				var url=data.url==undefined?"":data.url;	// 网址
				var profile=data.profile==undefined?"":data.profile;	// 简介
				m= "<div>"+
					"<span style=\"font-size:13px\">名称："+name+"</span><br>"+
					"<span style=\"font-size:13px\">行业："+category+"</span><br>"+
					"<span style=\"font-size:13px\">地址：<a href='javascript:void(0)' onclick=\"getmap('"+address+"')\">"+address+"</a></span><br>"+
					"<span style=\"font-size:13px\">网址：<a href='javascript:void(0)' onclick=\"getnetmap('"+url+"')\">"+url+"</a></span><br>"+
					"<span style=\"font-size:13px\">简介："+profile+"</span><br></div>";		          
			}
  }); 
	return m;
}	
function getmap(address){
	window.open(ctx+"/pro/project/getMapPage?address="+encodeURI(encodeURI(address)),"_blank"); 
	
}
function getnetmap(url){
	window.open(url,"_blank"); 
	
}
function popoverclient(id,clientid){
	$("#"+id).popover({
	    trigger:'manual',
	    placement : 'right', 
	    title : '', 
	    html: 'true', 
	    content : '', 
	    animation: false
	}).on("mouseleave", function () {
	    setTimeout(function () {
	        if (!$(".popover:hover").length) {
	        	$("#"+id).popover("hide")
	        }
	    }, 100);
	});
	//弹出
	 var Content1 = getClientInfo(clientid);
     $("#"+id).attr("data-content",Content1);
     $("#"+id).popover("show");
     $("#"+id).siblings(".popover").on("mouseleave", function () {
     	$("#"+id).popover('hide');
     });
}



/************************客户信息弹出框end****************************************/
jQuery(document).ready(function () {
	$(".popover-attr").popover({
	    trigger:'manual',
	    placement : 'right', //placement of the popover. also can use top, bottom, left or right
	    title : '', //this is the top title bar of the popover. add some basic css
	    html: 'true', //needed to show html of course
	    content : '', //this is the content of the html box. add the image here or anything you want really.
	    animation: false
	}).on("mouseenter", function () {
	            var _this = this;
	            var id = $(this).attr('id');
	            var Content1 = ContentMethod(id)//"<div>"+id+"</div>"
	            $(this).attr("data-content",Content1);
				 	$(this).popover("show");
	            $(this).siblings(".popover").on("mouseleave", function () {
	                $(_this).popover('hide');
	            });  
	           
	}).on("mouseleave", function () {
	    var _this = this;
	    setTimeout(function () {
	        if (!$(".popover:hover").length) {
	            $(_this).popover("hide")
	        }
	    }, 100);
	});
});
function popover(id,userid){
	$("#"+id).popover({
	    trigger:'manual',
	    placement : 'right', 
	    title : '', 
	    html: 'true', 
	    content : '', 
	    animation: false
	}).on("mouseleave", function () {
	    setTimeout(function () {
	        if (!$(".popover:hover").length) {
	        	$("#"+id).popover("hide")
	        }
	    }, 100);
	});
	//弹出
	 var Content1 = ContentMethod(userid);
     $("#"+id).attr("data-content",Content1);
     $("#"+id).popover("show");
     $("#"+id).siblings(".popover").on("mouseleave", function () {
     	$("#"+id).popover('hide');
     });
}
jQuery(document).ready(function () {
	$(".popover-attrmember").popover({
	    trigger:'focus',
	    placement : 'bottom', //placement of the popover. also can use top, bottom, left or right
	    title : '', //this is the top title bar of the popover. add some basic css
	    html: 'true', //needed to show html of course
	    content : '', //this is the content of the html box. add the image here or anything you want really.
	    animation: false
	}).on("mouseenter", function () {
	            var _this = this;
	            var id = $(this).attr('id');
	            var Content1 = ContentMethod1(id);//"<div>"+id+"</div>"
	            $(this).attr("data-content",Content1);
				 	$(this).popover("show");
	            $(this).siblings(".popover").on("mouseleave", function () {
	                $(_this).popover('hide');
	            });  
	         
	           
	}).on("mouseleave", function () {
	    var _this = this;
	    setTimeout(function () {
	        if (!$(".popover:hover").length) {
	            $(_this).popover("hide")
	        }
	    }, 100);
	});
});


//判断事件
function mouseOut(){
	$("#mouseOutId").parent().parent().attr("style","display:none");
}
//防止出现两个弹出框,解决弹出框不消失问题
function hiddenDiv(){
	  $("#popoverCloseId").parent().remove();
}
//打开私信的窗口
function showPrivate(proMemberId){
	$("#contentId").val("请输入私信内容");
	$("#proMemberId").val(proMemberId);
}

